//
//  ViewController.m
//  多组数据
//
//  Created by song on 15/1/10.
//  Copyright (c) 2015年 song. All rights reserved.
//

#import "ViewController.h"

#import "CarGroup.h"

@interface ViewController () <UITableViewDataSource>

@property (weak, nonatomic) IBOutlet UITableView *tableView;

@property (nonatomic , strong) NSArray *carGroup;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
   
    self.tableView.dataSource = self;
    
    
}

-(NSArray *)carGroup
{
    if(_carGroup ==nil)
    {
        
        CarGroup *cg1 = [[CarGroup alloc]init];
        cg1.title = @"德系品牌";
        cg1.desc =@"德系品牌很好";
        cg1.cars =@[@"宝马" ,@"奔跑",@"奥迪",@"宝马" ,@"奔跑",@"奥迪",@"宝马" ,@"奔跑",@"奥迪"];
        
        CarGroup *cg2 = [[CarGroup alloc]init];
        cg2.title = @"日韩品牌";
        cg2.desc =@"日韩品牌很好";
        cg2.cars =@[@"本田" ,@"丰田",@"宝马" ,@"奔跑",@"奥迪",@"宝马" ,@"奔跑",@"奥迪",@"宝马" ,@"奔跑",@"奥迪"];
        
        CarGroup *cg3 = [[CarGroup alloc]init];
        cg3.title = @"国美品牌";
        cg3.desc =@"国美品牌很好";
        cg3.cars =@[@"蓝魔" ,@"雪铁龙",@"宝马" ,@"奔跑",@"奥迪",@"宝马" ,@"奔跑",@"奥迪",@"宝马" ,@"奔跑",@"奥迪"];
        
        _carGroup =@[cg1 ,cg2 , cg3];
    }
    
    return _carGroup;
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return self.carGroup.count;
}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    NSLog(@"numberof RowsInSection  %d", section);
    
    CarGroup *cg = self.carGroup[section];
    
    return cg.cars.count;
    
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    UITableViewCell *cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
    
    
    CarGroup *cg = self.carGroup[indexPath.section];
    
    cell.textLabel.text =cg.cars[indexPath.row];

    return cell;
    
}

-(BOOL) prefersStatusBarHidden
{
    return YES;
}

//-(NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
//{
//    CarGroup *cg = self.carGroup[section];
//    return cg.title;
//}

-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    CarGroup *cg = self.carGroup[section];
    return cg.desc;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
